home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Debuggers & dcmds / MacsBug 6.5.2 / dcmds / C Samples / Heap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-26  |  2.2 KB  |  110 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Heap.c
  3.  
  4.     Contains:    A sample dcmd which dumps heap blocks.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.  
  8.     Copyright:    © 1988, 1994 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>   10-Dec-94    JM3        Updated for new format 3 dcmd requirements.
  13.          <2>    1-Sep-94    JM3        Included string.h so we build with no warnings with -r.
  14.  
  15. */
  16.  
  17.  
  18. #include <Memory.h>
  19. #include <Types.h>
  20. #include <string.h>
  21.  
  22. #include "dcmd.h"
  23.  
  24.  
  25. void NumberToHex (long number, Str255 hex)
  26. {
  27.  
  28.     Str255    digits = "0123456789ABCDEF";
  29.     int        n;
  30.  
  31.     strcpy (hex, &".00000000");
  32.     hex[0] = 8;
  33.  
  34.     for (n = 8; n >= 1; n--)
  35.     {
  36.         hex[n] = digits[number % 16];
  37.         number = number / 16;
  38.     }
  39.  
  40. } // NumberToHex
  41.  
  42.  
  43. pascal void DisplayBlockInfo (long blockAddress, long blockLength, long masterPtr, short blockType, Boolean locked, Boolean purgeable, Boolean resource)
  44. {
  45.  
  46.     Str255 value;
  47.  
  48.     NumberToHex (blockAddress, value);
  49.     dcmdDrawLine (value);
  50.  
  51.     NumberToHex (blockLength, value);
  52.     dcmdDrawString ("\p ");
  53.     dcmdDrawString (value);
  54.  
  55.     if (blockType == relocatableBlock)
  56.     {
  57.         NumberToHex (masterPtr, value);
  58.         dcmdDrawString ("\p ");
  59.         dcmdDrawString (value);
  60.  
  61.         dcmdDrawString ("\p ");
  62.         if (locked)
  63.             dcmdDrawString ("\pLocked ");
  64.         if (purgeable)
  65.             dcmdDrawString ("\pPurgeable ");
  66.         if (resource)
  67.             dcmdDrawString ("\pResource ");
  68.     }
  69.  
  70. } // DisplayBlockInfo
  71.  
  72.  
  73. pascal void CommandEntry (dcmdBlock* paramPtr)
  74. {
  75.  
  76.     static const char usageStr[] = "\p";
  77.  
  78.     switch (paramPtr->request)
  79.     {
  80.         case dcmdInit:
  81.             break;
  82.  
  83.         case dcmdHelp:
  84.             dcmdDrawLine("\pDisplays information about all heap blocks.");
  85.             break;
  86.  
  87.         case dcmdGetInfo:
  88.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
  89.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  90.             break;
  91.  
  92.         case dcmdDoIt:
  93.  
  94.             // Draw the column labels
  95.  
  96.             dcmdDrawLine ("\p  Address   Length  Mstr Ptr");
  97.  
  98.             // The MacsBug heap iterator will call DisplayBlockInfo once for each block in the heap.
  99.  
  100.             dcmdForAllHeapBlocks (DisplayBlockInfo);
  101.             break;
  102.  
  103.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  104.  
  105.         default:
  106.             break;
  107.     }
  108.  
  109. } // CommandEntry
  110.